OBJ := led
obj-m := $(OBJ).o
PWD := $(shell pwd)
CROSS_COMPILE := arm-linux-
CC  := $(CROSS_COMPILE)gcc
ROOTFS := /home/chzhou/code/2440/rootfs
MODULE_DIR := $(ROOTFS)/lib/modules/2.6.32.2
CP_DIR := $(ROOTFS)/bin

DEBUG = y
ifeq ($(DEBOG), y)
	EXTRA_FLAGS += -v
	CFLAGS += -v
endif
GCCPREFIX='v'

ifeq ($(CC), gcc)
	KDIR := /lib/modules/$(shell uname -r)/build
else
	KDIR := /home/chzhou/code/2440/kernel
endif

all: modules test

modules:
	@echo "PWD=$(PWD)"
	@echo "KDIR=$(KDIR)"
	@echo "CC=$(CC)"
	$(MAKE) -C $(KDIR) M=$(PWD) modules

test: $(OBJ)_test.c
	$(CC) -o $(OBJ)_test.o $<

.PHONY:
	clean install uninstall

clean:
	 rm -fr *.o *~core *.ko *.mod.c *.order *.symvers *.markers .*cmd .tmp_versions \
		 $(OBJ)_test.o

install:
	cp $(OBJ).ko $(MODULE_DIR)
	cp $(OBJ)_test.o $(CP_DIR)

uninstall:
	rm $(MODULE_DIR)/$(OBJ).ko
	rm $(CP_DIR)/$(OBJ)_test.o

